{% extends 'myadmin/index.html'%}

{% block title %}
<title>后台会员列表</title>
{% endblock %}

{% block con%}
<div class="widget-body  am-fr">

    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
        <div class="am-form-group">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                </div>
            </div>
        </div>
    </div>
     <form>
    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
        <div class="am-form-group tpl-table-list-select">
            <select data-am-selected="{btnSize: 'sm'}" style="display: none;" name="types">
              <!--<option value="all">全局搜索</option>-->
              <!--<option value="goodsname">商品名</option>-->
               <!--<option value="id">id</option>-->
                 <!--<option value="title">标题</option>-->
                 <option value="all" {% if request.GET.types == 'all' %} selected {% endif %}>全局搜索</option>
              <option value="id" {% if request.GET.types == 'id' %} selected {% endif %}>ID</option>
              <option value="goodsname" {% if request.GET.types == 'goodsname' %} selected {% endif %}>商品名</option>

                 <!--<option value="email">邮箱</option>-->
            </select>
        </div>
    </div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">

        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
            <input type="text" class="am-form-field" name="keyword" value="{{request.GET.keyword}}">
            <span class="am-input-group-btn">
                <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
              </span>
        </div>

    </div>
     </form>
    <div class="am-u-sm-12">
        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
            <thead>
                <tr>
                <th>ID</th>
                <th>缩略图</th>
                <th>商品名</th>
                <th>标题</th>
                <th>所属分类</th>
                <th>价格</th>
                <th>库存</th>
                <th>销量</th>
                <th>点击量</th>
                <th>状态</th>
                <th>注册时间</th>
                <th>操作</th>
                </tr>
            </thead>
            <tbody>
            {% for i in userlist%}
                <tr class="gradeX">
                    <td class="am-text-middle">{{i.id}}</td>
                    <td>
                        <img src="{{i.pic_url}}" class="tpl-table-line-img" alt="">
                    </td>
                    <td class="am-text-middle nikename" id="nikename" uid="{{i.id}}">{{i.goodsname}}</td>
                    <td class="am-text-middle">{{i.title}}</td>
                    <td class="am-text-middle">{{i.cateid.name}}</td>
                    <td class="am-text-middle">{{i.price}}</td>
                    <td class="am-text-middle">{{i.goodsunm}}</td>
                     <td class="am-text-middle">{{i.ordernum}}</td>
                    <td class="am-text-middle">{{i.clicknum}}</td>
                    <td class="am-text-middle">
                        <select uid="{{ i.id }}" class="select-status" style="color:red;">
                        <option value="0" {% if i.status == 0 %} selected {% endif %}>新品</option>
                        <option value="1" {% if i.status == 1 %} selected {% endif %}>热卖</option>
                         <option value="2" {% if i.status == 2 %} selected {% endif %}>推荐</option>
                         <option value="3" {% if i.status == 3 %} selected {% endif %}>下架</option>
                        </select>
                    </td>
                    <td class="am-text-middle">{{i.addtime}}</td>
                    <td class="am-text-middle">
                        <div class="tpl-table-black-operation">
                            <a href="{% url 'goods_edit' %}?id={{i.id}}">
                                <i class="am-icon-pencil"></i> 编辑
                            </a>
                            <a href="{% url 'goods_del' %}?id={{ i.id }}" class="tpl-table-black-operation-del">
                                <i class="am-icon-trash"></i> 删除
                            </a>
                        </div>
                    </td>
                </tr>
            {% endfor %}
                <!-- more data -->
            </tbody>
        </table>
    </div>
    <div class="am-u-lg-12 am-cf">

        <div class="am-fr">
            <ul class="am-pagination tpl-pagination">
             {% load pagetag %}
                <!--调用自定义标签函数  第一个参数是总条目 第二个参数是当前的页数(request是后台接受的get参数)  -->
             {% showpage userlist.paginator.num_pages request %}

            </ul>
        </div>
    </div>
</div>
<script>
    $('.select-status').change(function(){
        //alert(1)
        var status=$(this).val()

        var uid=$(this).attr('uid')

        $.get('{%url 'goods_status'%}',{'uid':uid,'status':status},function(data){
            alert('修改成功')
        },'json')
    })
    //未完善
    $('.nikename').dblclick(function(){
        var nikename=$(this).text()
        $(this).text('')
        //获取uid
        uid=$(this).attr('uid')
        //alert(uid)
        //alert(nikename)
        then=$(this)
        $(this).append('<input  id="nike"  name="nikename" type="text" value="'+nikename+'" style="background:#000">')
        $('body').on('blur','#nike',function(){
            nikename=$('#nike').val()
            //alert(nikename)
            $.get('{%url 'goodsname'%}',{'uid':uid,'nikename':nikename},function(data){
                $('#nike').remove()
                then.append('<label>'+nikename+'</label>')
                nikename=''
                then=''
                //alert('修改成功')
            },'json')
        })
    })

$(document).ready(function(){
   $('#shangpinguanli').click()
})

</script>
{%endblock%}